Number.prototype.toMoney = function(decimals, decimal_sep, thousands_sep){ 
    var n = this,
    c = isNaN(decimals) ? 2 : Math.abs(decimals), //if decimal is zero we must take it, it means user does not want to show any decimal
    d = decimal_sep || '.', //if no decimal separator is passed we use the dot as default decimal separator (we MUST use a decimal separator)

    t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, //if you don't want to use a thousands separator you can pass empty string as thousands_sep value

    sign = (n < 0) ? '-' : '',

    //extracting the absolute value of the integer part of the number and converting to string
    i = parseInt(n = Math.abs(n).toFixed(c)) + '', 

    j = ((j = i.length) > 3) ? j % 3 : 0; 
    return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ''); 
}

$(window).load(function() {
	//set image product
    $(".image-item img").each(function(){
        imgWidth = $(this).width();
        imgHeight = $(this).height();
        var setWidth = (imgWidth*235)/imgHeight;
        var setHeight = (imgHeight*210)/imgWidth;
        var setImgLeft = (-(setWidth-210)/2);
        var setImgTop = (235-setHeight)/2;
        if((imgWidth/imgHeight) >= 2){
            $(this).css({
                'top' : setImgTop + "px",
                'width' : 210 + "px"
            });
        }
        else{
            $(this).css({
                'left' : setImgLeft + "px",
                'height' : 235 + "px"
            });
        }
    });

	//categories second slider
    $('#catsecond-slider').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 5000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: true, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: true, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg'/*tpa=http://naima.vn/assets/8842a280/js/_thumb.jpg*/, // ...this in thumb Image src
        keyboardNav: true, // Use left & right arrows
        pauseOnHover: false, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 0.6, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        randomStart: false, // Start on a random slide
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
	
    //promotion slider
    $('#promotion-slider').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 5000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: true, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: true, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg'/*tpa=http://naima.vn/assets/8842a280/js/_thumb.jpg*/, // ...this in thumb Image src
        keyboardNav: true, // Use left & right arrows
        pauseOnHover: false, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 0.6, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        randomStart: false, // Start on a random slide
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });	
	
});

$(document).ready(function(){
	
    //categories slider
    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 1,
        auto: 5,
        animation: 800,
        wrap: 'last'
    });
	
    //cat second slider
    jQuery('#catsecond-thumbs').jcarousel({
        scroll: 1,
        auto: 0,
        animation: 500
    });
	
    //slider item product
    jQuery('.small-slider').jcarousel({
        scroll: 1,
        auto: 0,
        animation: 500
    });
	
    //categories slider
    jQuery('#product-same').jcarousel({
        vertical: true,
        scroll: 1,
        auto: 5,
        animation: 1000,
        wrap: 'last'
    });
	
    //menu first
    $('.first-link', $('.menu-left ul')).live("click", function(){
        var parent = $(this).parent();
        if ($(parent).hasClass("active")){
            $(parent).removeClass("active");
        }else{
            $('li', $('.menu-left ul')).removeClass("active");
            $(parent).addClass("active");
        }    	
        return true;
    });
    //menu second
    $('.second-link', $('.menu-left ul li.active ul li')).live("click", function(){
        var parent = $(this).parent();
        if ($(parent).hasClass("active")){
            $(parent).removeClass("active");
        }else{
            $('li', $('.menu-left ul li ul')).removeClass("active");
            $(parent).addClass("active");
        }    	
        return true;
    });
    //menu three
    $('.three-link', $('.menu-left ul li ul li ul li')).live("click", function(){
        var parent = $(this).parent();
        if ($(parent).hasClass("active")){
            $(parent).removeClass("active");
        }else{
            $('li', $('.menu-left ul li ul li ul')).removeClass("active");
            $(parent).addClass("active");
        }    	
        return true;
    });
	
    //size product filter
    $('.size-item', $('.box-size')).live("click", function(){
        if ($(this).hasClass("selected")){
            $(this).removeClass("selected");
        }else{
            $(this).addClass("selected");
        }    	
        return true;
    });
	
    //main slider
    $('#slides').slides({
        generateNextPrev: true,
        play: 5000,
        pause: 5000,
        fadeSpeed: 500,
        effect: 'fade',
        autoHeight: false,
        autoWidth: true
    });
	
    //tab product
    $(".main-content").hide();
    $(".pd-tabs li:first").addClass("active").show();
    $(".main-content:first").show();
    //On Click Event
    $(".pd-tabs a").click(function() {
        $(".pd-tabs li").removeClass("active"); 
        var parent = $(this).parent();
        $(parent).addClass("active"); 
        $(".main-content").hide();
        var activeTab = $(this).attr("href");
        $(activeTab).fadeIn();
        return false;
    });
	
	//Scroll bar cart
	$('#cart-list').slimScroll({
		height: '200px',
		width: '320px'
	});
   
});

//function show or hide footer
function showFooter(){
    $('#footer-expand').live("click", function(){
        $('#footer-content').slideDown();
        $('#footer-close').css("display","block");
        $('#footer-expand').css("display","none");
    });
}
function hideFooter(){
    $('#footer-close').live("click", function(){
        $('#footer-content').slideUp();
        $('#footer-expand').css("display","block");
        $('#footer-close').css("display","none");
    });
}

//show or hide your menu showcart
$('.hide-menu').live("click", function(){
    var parent = $(this).parent();
    $(parent).removeClass("active");
    $('.ym-content',$(parent)).fadeOut('fast');
});
$('.show-menu').live("click", function(){
    var parent = $(this).parent();
    $(parent).addClass("active");
    $('.ym-content',$(parent)).fadeIn('fast');
});

//hide & show brand list
$('.close-ovelay', $('.box-ovelay')).live("click", function(){
    var rootgrand = $(this).parent().parent().parent();
    $('.btn-hidebrand', $(rootgrand)).css("display","none");
    $('.btn-allbrand', $(rootgrand)).css("display","block");
    $('.box-ovelay', $(rootgrand)).css("display","none");
});
$('.btn-allbrand', $('.box-filter')).live("click", function(){
    var rootgrand = $(this).parent().parent().parent();
    $(this).css("display","none");
    $('.btn-hidebrand', $(rootgrand)).css("display","block");
    $('.box-ovelay', $(rootgrand)).css("display","block");
});
$('.btn-hidebrand', $('.box-filter')).live("click", function(){
    var rootgrand = $(this).parent().parent().parent();
    $(this).css("display","none");
    $('.btn-allbrand', $(rootgrand)).css("display","block");
    $('.box-ovelay', $(rootgrand)).css("display","none");
});

//hide email promotion
$('.hide-email').live("click", function(){
    var parent = $(this).parent();
    $(parent).fadeOut('fast');
});

//show or hide faq
$('.faq-list .g-title').live("click", function(){
    var parent = $(this).parent().parent();
    if ($(parent).hasClass("active")){
			$('.faq-answer',$(parent)).fadeOut(100);
            $(parent).removeClass("active");
        }else{
			$('.faq-answer',$('.faq-list')).fadeOut(100);
			$('.grid', $('.faq-list')).removeClass("active");         
			$('.faq-answer',$(parent)).fadeIn('slow');
			$(parent).addClass("active");
        }    	
        return true;
});
$('.faq-list .more').live("click", function(){
    var parent = $(this).parent().parent().parent();
	$('.faq-answer',$(parent)).fadeOut(100);
	$(parent).removeClass("active");
});

//Call Box move when add Item in Cart
function pussCart(){
    var source = $('#btn-pdcart-id');
    var target = $('#box-cart-id');
    $('body').prepend('<div id="shadow-item" style="display: none; background-color: #ddd; border: solid 1px darkgray; position: static; top: 0px; z-index: 1990;">&nbsp;</div>');
    var shadow = $('#shadow-item');
    shadow.width(source.css('width')).height(source.css('height')).css('top', source.offset().top).css('left', source.offset().left).css('opacity', 0.7).show();
    shadow.css('position', 'absolute');
    shadow.animate({ width: target.innerWidth(), height: target.innerHeight(), top: target.offset().top, left: target.offset().left }, { duration: 1000 })
            .animate({ opacity: 0 }, { duration: 100, complete: function () {
                    shadow.empty().hide();
            }
    });
}